<?php
/*
商家同意退货与否
*/

include('../conn.php');
// require('../../tool/UpFileTool.class.php');
require('../../tool/UploadImage.class.php');
// 需传参数 
$id=$_REQUEST['id'];
$state=$_REQUEST['state'];
$shop_images = $_FILES['shop_images'];
$shop_comment = $_REQUEST['shop_comment'];
$address = $_REQUEST['address'];
$phone = $_REQUEST['phone'];
// 需传参数 end

// 状态
$state5 = 5;
$twodays = 2;
// 状态 end
$addtime = date("Y-m-d H:i:s");

if ($id != '' && ($state==2 || $state==3)) {

	// 查询商家是否已经发货
	$query = mysql_query("select orderstate from tuihuo where id=".$id);
	$tuihuo = mysql_fetch_assoc($query);
	$orderstate = $tuihuo['orderstate'];
	// 查询商家是否已经发货 end
	if ($orderstate == 2 || $orderstate == 3) {
		$shop_images = '';
		$shop_srcimages = '';
		$upload = new Upload("shop_images");
		$date = date('Y-m-d');
		$sumbimage = '../../sumbimage/'.$date;
		$srcimage = '../../srcimage/'.$date;
		$upload->setFilePath($srcimage);
		$upload->setSmallFilePath($sumbimage);
		$re = $upload->upload();
		if($re){
			$path = $upload->getPath();
			$smallPath = $upload->getSmallimg();
			
			foreach ($path as $key => $value) {
				$path[$key] = 'srcimage/'.$date.'/'.$value;
				$smallPath[$key] = 'sumbimage/'.$date.'/'.$smallPath[$key];
			}
		
			$shop_srcimages = implode(',',$path);
			$shop_images = implode(',',$smallPath);
		}
		// 	$UpFileTool=new UpFileTool('shop_images');
		// 	$UpFileTool->multiImage($w=500, $h=500 ,$sumbimage='../../sumbimage', $srcimage='../../srcimage');
		// 	$shop_images = $UpFileTool->multiSumbImage;
		// 	$shop_srcimages = $UpFileTool->multiSrcImage;
		// }

		$query  = mysql_query("UPDATE tuihuo SET phone='".$phone."',state=".$state.",shop_comment='".$shop_comment."',shop_images='".$shop_images."',shop_srcimages='".$shop_srcimages."',address='".$address."',`2time`='".$addtime."' where id=".$id);
		
		if (mysql_affected_rows()>0) {
			if ($state == 2) {
				$arr = array('code' => 200, 'id' => $id, 'tip' =>'商家同意退货');
			}elseif ($state==3) {
				$arr = array('code' => 200, 'id' => $id, 'tip' =>'商家不同意退货');
				// 定时器
				$url = "http://120.24.0.10/xzpf/changeAfterTime/changeTuihuoState.php?id=".$id."";

				$start_date = date("Y-m-d",strtotime(''.$twodays.'days'));
				$start_hour = date("H");
				$start_minute = date("i");
				$tag = 'setTuihuoState';
				$loop = 1;

				$apiUrl = "http://120.24.0.10/unitask/core/func.add.php?url=".$url."&start_date=".$start_date."&start_hour=".$start_hour."&start_minute=".$start_minute."&tag=".$tag."&loop=".$loop."";
				file_get_contents($apiUrl);
				// 定时器 end
			}
		}else{
			$arr = array('code' => 201, 'tip' =>'未更改数据');
		}
	}else{
		$query = mysql_query("UPDATE tuihuo set state=".$state5 ." where id=".$id);
		if (mysql_affected_rows()>0) {
			$arr = array('code' => 200, 'tip' =>'成功');
		}else{
			$arr = array('code' => 201, 'tip' =>'未更改数据');
		}
	}

}else{
	$arr = array('code' => 400, 'tip' =>'参数传入有误,必传入参数:退货id=>id,审核状态=>state(2为商家同意退货,3为商家不同意退货);可选参数:商家审核退货不通过说明=>shop_comment,商家审核退货不通过说明附图=>shop_images');
}

echo json_encode($arr);

?>